﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.GetRecipientListRequest
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Microsoft.InfoCards
{
  internal class GetRecipientListRequest : UIAgentRequest
  {
    private IList<Recipient> m_recipientList;

    public GetRecipientListRequest(
      IntPtr rpcHandle,
      Stream inArgs,
      Stream outArgs,
      ClientUIRequest parent)
      : base(rpcHandle, inArgs, outArgs, parent)
    {
    }

    protected override void OnMarshalInArgs()
    {
    }

    protected override void OnProcess()
    {
      StoreConnection connection = StoreConnection.GetConnection();
      try
      {
        IList<DataRow> dataRowList = (IList<DataRow>) connection.Query(QueryDetails.FullRow, new QueryParameter("ix_objecttype", new object[1]
        {
          (object) -3
        }));
        if (dataRowList == null)
          return;
        IList<Recipient> recipientList = (IList<Recipient>) new List<Recipient>(dataRowList.Count);
        foreach (DataRow dataRow in (IEnumerable<DataRow>) dataRowList)
          recipientList.Add(new Recipient((Stream) new MemoryStream(dataRow.GetDataField())));
        this.m_recipientList = recipientList;
      }
      finally
      {
        connection.Close();
      }
    }

    protected override void OnMarshalOutArgs()
    {
      BinaryWriter writer = new BinaryWriter(this.OutArgs, Encoding.Unicode);
      uint num = 0;
      if (this.m_recipientList != null)
      {
        uint count = (uint) this.m_recipientList.Count;
        writer.Write(count);
        foreach (Recipient recipient in (IEnumerable<Recipient>) this.m_recipientList)
          recipient.Serialize(writer);
      }
      else
        writer.Write(num);
    }
  }
}
